package org.example.entity;

/**
 * 用户角色枚举
 */
public enum UserRole {
    ADMIN("管理员"),
    USER("普通用户"),
    MAINTENANCE("维修师傅");

    private final String description;

    UserRole(String description) {
        this.description = description;
    }

    public String getDescription() {
        return description;
    }

    /**
     * 检查是否为管理员
     */
    public boolean isAdmin() {
        return this == ADMIN;
    }

    /**
     * 检查是否为维修师傅
     */
    public boolean isMaintenance() {
        return this == MAINTENANCE;
    }

    /**
     * 检查是否为普通用户
     */
    public boolean isUser() {
        return this == USER;
    }

    /**
     * 检查是否有管理权限（管理员或维修师傅）
     */
    public boolean hasAdminPrivileges() {
        return this == ADMIN || this == MAINTENANCE;
    }

    /**
     * 从字符串获取角色
     */
    public static UserRole fromString(String role) {
        if (role == null) {
            return USER;
        }
        try {
            return UserRole.valueOf(role.toUpperCase());
        } catch (IllegalArgumentException e) {
            return USER;
        }
    }
}
